package com.dog.basics.admin.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.mtkj.LockAddDto;
import com.dog.basics.bean.dto.admin.mtkj.LockEditDto;
import com.dog.basics.bean.dto.admin.mtkj.LockFromDto;
import com.dog.basics.bean.vo.admin.mtkj.LockVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.mtkj.IMtDeviceLockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;

/**
 * <p>
 * 设备锁 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-09-29
 */
@RestController
@RequestMapping("/pc/device/lock")
@Api(value = "设备锁模块", tags = "设备锁模块")
@AllArgsConstructor
public class MtDeviceLockController {
    private final IMtDeviceLockService mtDeviceLockService;

    /**
     * @Description: 设备锁列表
     * @Param: LockFromDto
     * @return: IPage<LockVo>
     * @Author: wph
     * @Date:
     */

    @ApiOperation(value = "设备锁列表", notes = "pc:mtDeviceLock:page")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('pc:mtDeviceLock:page')")
    public R<IPage<LockVo>> page(PageParam page, LockFromDto obj) {
        IPage<LockVo> list = mtDeviceLockService.getPageList(page, obj);
        return R.ok(list);
    }

    /**
     * @Description: 增加设备锁
     * @Param: LockAddDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("增加设备锁")
    @ApiOperation(value = "增加设备锁", notes = "pc:mtDeviceLock:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('pc:mtDeviceLock:save')")
    public R<Boolean> save(@Valid @RequestBody LockAddDto obj) {
        return R.ok(mtDeviceLockService.saveObj(obj));
    }

    /**
     * @Description: 删除设备锁
     * @Param: ids
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("删除设备锁")
    @ApiOperation(value = "删除设备锁", notes = "pc:mtDeviceLock:delete")
    @ApiImplicitParam(value = "设备锁Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('pc:mtDeviceLock:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(mtDeviceLockService.deleteObj(id));
    }

    /**
     * @Description: 修改设备锁
     * @Param: LockEditDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("修改设备锁")
    @ApiOperation(value = "修改设备锁", notes = "pc:mtDeviceLock:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('pc:mtDeviceLock:edit')")
    public R<Boolean> edit(@Valid @RequestBody LockEditDto obj) {
        return R.ok(mtDeviceLockService.editObj(obj));
    }
    /**
     * @Description: 设备锁在线离线
     * @Param: LockEditDto
     * @return: Boolean
     * @Author: wph
     * @Date: 2020/05/19  0027
     */
    @SysLog("设备锁在线离线")
    @ApiOperation(value = "设备锁在线离线", notes = "pc:mtDeviceLock:online")
    @ApiImplicitParam(value = "设备锁Id", name = "id", dataType = "Long", required = true)
    @PutMapping("/edit/{id}")
    @PreAuthorize("@pms.hasPermission('pc:mtDeviceLock:online')")
    public R<Boolean> editOnline(@PathVariable("id") Long id) {
        return R.ok(mtDeviceLockService.editOnline(id));
    }
}
